package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import lombok.Getter;
import lombok.Setter;

import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class Order extends BaseDomain {
    //已加入购物车
    public static final Integer STATE_ADD = 1;
    //已支付成功
    public static final Integer STATE_PAY = 2;
    /**
     * 订单用户
     */
    private User user;
    /**
     * 订单总积分
     */
    private Integer totalIntegral;
    /**
     * 订单编号
     */
    private String sn;
    /**
     * 订单状态
     */
    private Integer state;

    /**
     * 商品名称
     */
    private String goodsName;
    /**
     * 商品封面
     */
    private String goodsCoverUrl;

    public String getJson() {
        Map<String, Object> map = new HashMap<>();
        map.put("id", id);
        map.put("totalIntegral", totalIntegral);
        map.put("sn", sn);
        map.put("state", state);
        map.put("goodsName", goodsName);
        map.put("goodsCoverUrl", goodsCoverUrl);
        if (user != null) {
            map.put("userId", user.getId());
            map.put("userNickName", user.getNickName());
        }
        return JSONUtil.toJSONString(map);
    }

    public String getStateName() {
        String temp = "";
        if (state.equals(STATE_ADD)) {
            temp = "已加购";
        } else if (state.equals(STATE_PAY)) {
            temp = "已支付";
        }
        return temp;
    }
}